package demo02

/**
 * @author xiaoZhao
 * @date 2022/6/20
 * @describe
 */
object Test07_DataTypeConversion {
  def main(args: Array[String]): Unit = {
    // 1.自动类型转换
    val a1: Byte = 10;
    val b1: Long = 20L;
    val result1: Long = a1 + b1
    println(result1)

    val a2: Byte = 10
    val b2: Int = a2
    val c2: Byte = b2.toByte

    // 2.强制类型转换
    val n1: Int = 2.5.toInt
    println(n1)

    val n2: Int = (2.6 + 3.7).toInt
    println(n2)

    // 3.数值类型和String类型
    // 数值转为String
    val a: Int = 27
    val s: String = a + " "
    println(s)

    //String转换为数值
    val m: Int = "12".toInt
    val f: Float = "12.4".toFloat
    val f2: Int = "12.6".toFloat.toInt
    println(f2)
  }
}
